package com.common.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.companyname.projecttemplate.ws.AppWebSocketHandler;
import com.companyname.projecttemplate.ws.AuthorityHandshakeInterceptor;

/**
 * websocket配置
 * @author zywei
 *
 */
@Configuration
@EnableWebSocket
public class WsConfiguration implements WebSocketConfigurer {

    @Autowired
    private AppWebSocketHandler appWebSocketHandler;
	@Autowired
	private AuthorityHandshakeInterceptor authorityHandshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(appWebSocketHandler, "/wsock/test")
                .addInterceptors(authorityHandshakeInterceptor)
                .setAllowedOriginPatterns(CorsConfiguration.ALL);
    }
    
}
